<template>
  <div class="albums">
    <ThumbnailLoading v-if="list.length===0"></ThumbnailLoading>
    <div v-else>
      <AlbumsHead>
         <div>全部音单</div>
        <div slot="btn" @click="showMenu" class="albumsnav">
          <span>类型</span>
        </div>
      </AlbumsHead>
      <AlbumsBody :key="page" :page="page" @getMore="getMore" :list="list"></AlbumsBody>
      <transition enter-active-class="animated slideInRight" leave-active-class="animated slideOutRight">
        <AlbumsMenu v-bind="$listeners" v-show="ifShow" @showMenu="showMenu" @changeType="changeType"></AlbumsMenu>
      </transition>
    </div>
  </div>
</template>

<script>
import ThumbnailLoading from "components/public/ThumbnailLoading"
import AlbumsHead from "components/home/albums/AlbumsHead"
import AlbumsBody from "components/home/albums/AlbumsBody"
import AlbumsMenu from "components/home/albums/AlbumsMenu"
import { get } from "util/http"
export default {
  data(){
    return {
      list:[],
      page:0,
      tid:this.$route.params.id?this.$route.params.id:0,
      ifShow:false
    }
  },
  methods:{
    async getMore(){
      if(this.ifOk&&this.page<1){
        this.ifOk=false
        this.page++
        let page=this.page
        let tid=this.tid
        let result=await get({
          url:"/ajax/explore/tagalbum",
          params:{
            order:page,
            tid:tid
          }
        })
      this.list=[
        ...this.list,
        ...result.albums
        ]
        await this.$nextTick()
        this.ifOk=true
      }
    },
    showMenu(){
      this.ifShow=!this.ifShow
    },
    async changeType(obj){
      
      this.tid=obj.id
      this.page=0
      await this.start()
    },
    async start(){
      this.ifOk=true
      let page=this.page
      let tid=this.tid
      let result=await get({
        url:"/ajax/explore/tagalbum",
        params:{
          order:page,
          tid:tid
        }
      })
      this.list=result.albums
    }
  },
  async mounted(){
   await this.start()
  },
  components:{
    ThumbnailLoading,
    AlbumsHead,
    AlbumsBody,
    AlbumsMenu
  }
}
</script>

<style lang="stylus" scoped>
.albums
  width 100%
  margin .1rem auto
  flex 1
  display flex
  flex-direction column
  justify-content center
  .albumsnav
        font-size .14rem
        color #9e9e9e
        >span 
            display flex
            align-items center
            justify-content center
            border .01rem solid #e0e0e0
            border-radius .2rem
            width .64rem
            height .24rem
            font-size .13rem
            color #757575
            text-align center
            background #fff
        >span:after
            content ""
            display block
            width .08rem
            height .08rem
            border .01rem solid #757575
            border-bottom none 
            border-left none
            transform rotate(45deg)

</style>